from sys import *
from scipy import *

class simplex :
	def __init__(self, input) :
		self.matrix = array(input,dtype = float32)
	
	def show(self) :
		print self.matrix
	
	def pivo(self, i, j) :
		m = shape(self.matrix)[0]
		n = shape(self.matrix)[1]
		if i < m and j < n :
			valorPivo = self.matrix[i][j]
			for jAux in xrange(n) :
				self.matrix[i][jAux] = self.matrix[i][jAux]/valorPivo
			for iAux in xrange(m) :
				if iAux != i :
					mult = self.matrix[iAux][j]
					for jAux in xrange(n) :
						self.matrix[iAux][jAux] = self.matrix[iAux][jAux] - mult*self.matrix[i][jAux]
	
	def tab2tex(self) :
		m = shape(self.matrix)[0]
		n = shape(self.matrix)[1]
		stdout.write("\\begin{table}[!htb]\n\\centering\n\\begin{tabular}{|")
		for iAux in xrange(n) :
			stdout.write("c|")
		stdout.write("}\n")
		for iAux in xrange(m) :
			stdout.write("\\hline ")
			for jAux in xrange(n-1) :
				stdout.write("%.4f & " % (self.matrix[iAux][jAux]))
			stdout.write("%.4f \\\\\n" % (self.matrix[iAux][n-1]))
		stdout.write("\\hline\n\\end{tabular}\n\\end{table}\n")